VBcoders Browse New Submit Contact Sign In

No account? Register free

Forgot password?

Relative Path Function
Gets the relative path of a file w.r.t. a directory

Manas Tungare  (1 Submission)   Files/File Controls/Input/Output   Visual Basic 3.0   Intermediate   Wed 3rd February 2021

A reusable function that computes the relative path of a file with respect to a given directory


Examples will make the point clear, so here goes:



  1. GetRelativePath ("C:\VB\", "C:\VB\File.ext")
    returns "File.ext"


  2. GetRelativePath ("C:\VB\", "C:\VB\Program\File.ext")
    returns "Program\File.ext"


  3. GetRelativePath ("C:\VB\", "C:\File.ext")
    returns "..\File.ext"




It is useful to insert images and hyperlinks into webpages, given the filenames of the images and the HTML file.

Inputs

  1. sBase
    Fully Qualified Path of the Base Directory

  2. sFile
    Fully Qualified Path of the File of which the relative path is to be computed.

Assumes
Just remember to pass *complete* qualified paths to it. The CommonDialog.Filename property can be directly assigned in the call. e.g.

GetRelativePath ("C:\VB\", CommonDialog1.Filename)

Returns

Relative Path of sFile with respect to sBase.

Side Effects

None.

Rate Relative Path Function
Gets the relative path of a file w.r.t. a directory
(4(4 Vote))
Relative Path Function
Gets the relative path of a file w.r.t. a directory.bas

Relative Path Function
Gets the relative path of a file w.r.t. a directory Comments

No comments yet — be the first to post one!

Post a Comment

0/1000 characters